package com.funny.factoryprocessor;

import com.funny.service.TestServiceA;
import com.funny.service.TestServiceB;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author fanxiao  2021/8/9
 * @since 1.0.0
 */
@Slf4j
@Component
public class TestServiceBeanFactoryProcessor implements BeanFactoryPostProcessor {

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		ScannedGenericBeanDefinition scannedGenericBeanDefinition = (ScannedGenericBeanDefinition)
				beanFactory.getBeanDefinition("testServiceA");

		scannedGenericBeanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

		beanFactory.ignoreDependencyType(TestServiceB.class);
	}
}
